<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css" class="css">
			/*
				n 边形的外交和为 360 
				单个外角 360/n
				n 边形的内角 180 - 360/n
			*/
			*{
				margin: 0px;
				padding: 0px;
			}
			html,
			body{
				width: 100%;
				height: 100%;
				overflow: hidden;
			}
			.wrap{
				position: absolute;
				top: 0px;
				right: 0px;
				bottom: 0px;
				left: 0px;
				margin: auto;
				
				width: 300px;
				height: 300px;
				border: 1px solid;
				
				perspective: 200px;
				/* transform-style: preserve-3d; */
			}
			.wrap > .box{
				position: absolute;
				top: 0px;
				right: 0px;
				bottom: 0px;
				left: 0px;
				margin: auto;
				
				width: 100px;
				height: 100px;
				transition: 1s transform;
				/* transform-origin: center center -28.8675px; */
				transform-style: preserve-3d;
			}
			.wrap > .box > div{
				position: absolute;
				
				width: 100px;
				height: 100px;
				background-color: pink;
				text-align: center;
				font: 30px/100px "微软雅黑";
				backface-visibility: hidden;
				/* transform-origin: center center -28.8675px; */
			}
			/* .wrap > .box > div:nth-child(1){
				transform: rotateY(0deg);
			}
			.wrap > .box > div:nth-child(2){
				transform: rotateY(120deg);
			}
			.wrap > .box > div:nth-child(3){
				transform: rotateY(240deg);
			} */
			.wrap:hover .box{
				transform: rotateY(360deg);
			}
		</style>
	</head>
	<body>
		<div class="wrap">
			<div class="box">
			</div>
		</div>
	</body>
	<script type="text/javascript">
		window.onload = function() {
			// 生成 n 棱柱
			function createLZ(n) {
				var boxNode = document.querySelector(".wrap > .box");
				var styleNode = document.createElement("style");
				// 外角
				var degOut = 360 / n;
				// 内角
				var degIn = 180 - degOut;
				var text = "";
				var cssText = "";
				for (var i = 0; i < n; i++) {
					text += "<div>" + (i + 1) + "</div>";
				}
				boxNode.innerHTML = text;
				var mainNode = document.querySelector(".wrap > .box > div");
				// 棱长
				var lengthL = mainNode.offsetWidth;
				for (var i = 0; i < n; i++) {
					cssText += ".wrap > .box > div:nth-child(" + (i + 1) + "){transform: rotateY(" + (i * degOut) + "deg);}";
				}
				cssText += ".wrap > .box, .wrap > .box > div{transform-origin: center center -" + (lengthL / 2 * Math.tan(degIn / 2 * Math.PI / 180)) + "px;}";
				styleNode.innerHTML = cssText;
				document.head.appendChild(styleNode);
			}
			createLZ(7);
		};
	</script>
</html>
